﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;

namespace Defect_Tracking_System
{
    // Note: For instructions on enabling IIS6 or IIS7 classic mode, 
    // visit http://go.microsoft.com/?LinkId=9394801

    public class MvcApplication : System.Web.HttpApplication
    {
        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            routes.MapRoute(
              "GroupIndex", // Route name
              "Group/Index/{PageIndex}/{keyWord}/{returnType}", // URL with parameters
              new { controller = "Group", action = "Index", PageIndex = UrlParameter.Optional, keyWord = UrlParameter.Optional, returnType = UrlParameter.Optional } // Parameter defaults
            );

            routes.MapRoute(
              "SearchUser", // Route name
              "Account/Search/{Keyword}", // URL with parameters
              new { controller = "Account", action = "Search"} // Parameter defaults
            );

            routes.MapRoute(
                "DeleteDefect", // Route name
                "Defect/DeleteDefect/{defectId}/{PageIndex}/{Type}", // URL with parameters
                new { controller = "Defect", action = "DeleteDefect", defectId = @"\w{8}-\w{4}-\w{4}-\w{4}-\w{12}", PageIndex = 1, Type = "All" } // Parameter defaults
            );

            routes.MapRoute(
                "ResetPassword", // Route name
                "Account/ResetPassword/Email/ReturnUrl", // URL with parameters
                new { controller = "Account", action = "ResetPassword" } // Parameter defaults
            );

            routes.MapRoute(
                "DefectDetails", // Route name
                "Defect/Details/{DefectId}/{PageIndex}", // URL with parameters
                new { controller = "Defect", action = "Details", DefectId = @"\w{8}-\w{4}-\w{4}-\w{4}-\w{12}", PageIndex = 1 } // Parameter defaults
            );

            routes.MapRoute(
                "AccountIndex", // Route name
                "Account/Index/{PageIndex}", // URL with parameters
                new { controller = "Account", action = "Index", PageIndex = UrlParameter.Optional } // Parameter defaults
            );

            routes.MapRoute(
                "AddRemoveProjectMember", // Route name
                "Project/AddRemoveProjectMember/{AccountId}/{ProjectId}/{GroupMemberPageIndex}/{ProjectMemberPageIndex}/{Method}/{KeyWord}/{ReturnType}/{IsAssigned}", // URL with parameters
                new { controller = "Project", action = "AddRemoveProjectMember", AccountId = @"\w{8}-\w{4}-\w{4}-\w{4}-\w{12}", ProjectId = @"\w{8}-\w{4}-\w{4}-\w{4}-\w{12}", GroupMemberPageIndex = 1, ProjectMemberPageIndex = 1, Method = "Add", KeyWord = "Search Member", ReturnType = "View", IsAssigned = false} // Parameter defaults
            );

            routes.MapRoute(
                "ViewDefect", // Route name
                "Defect/Index/{type}/{PageIndex}/{projectId}", // URL with parameters
                new { controller = "Defect", action = "Index", type = UrlParameter.Optional, PageIndex = UrlParameter.Optional, projectId = UrlParameter.Optional } // Parameter defaults
            );

            routes.MapRoute(
                "SearchMemberAjax", // Route name
                "Project/SearchMember/{projectId}/{keyWord}", // URL with parameters
                new { controller = "Project", action = "SearchMember" } // Parameter defaults
            );

            routes.MapRoute(
               "SearchProject", // Route name
               "Project/SearchProject/{Keyword}", // URL with parameters
               new { controller = "Project", action = "SearchProject", Keyword = UrlParameter.Optional } // Parameter defaults
            );

            routes.MapRoute(
                "DeleteAccount", // Route name
                "Account/Delete/{UserName}", // URL with parameters
                new { controller = "Account", action = "Delete" } // Parameter defaults
            );

            routes.MapRoute(
                "ChangeProjectUser", // Route name
                "Project/ChangeProjectMember/{ProjectId}/{projectMemberPageIndex}/{accountPageIndex}/{keyWord}", // URL with parameters
                new { controller = "Project", action = "ChangeProjectMember", ProjectId = @"\w{8}-\w{4}-\w{4}-\w{4}-\w{12}", projectMemberPageIndex = 1, accountPageIndex = 1, keyWord = "Search Member" } // Parameter defaults
            );
			
            routes.MapRoute(
                "EditClient", // Route name
                "Client/Edit/{ClientId}", // URL with parameters
                new { controller = "Client", action = "Edit" } // Parameter defaults
            );

            routes.MapRoute(
                "ReportResolution", // Route name
                "Defect/Resolution/{DefectId}", // URL with parameters
                new { controller = "Defect", action = "Resolution" } // Parameter defaults
            );

            routes.MapRoute(
                "EditDefect", // Route name
                "Defect/Edit/{DefectId}", // URL with parameters
                new { controller = "Defect", action = "Edit" } // Parameter defaults
            );
            
            routes.MapRoute(
                "EditUser", // Route name
                "Account/Edit/{EditUser}", // URL with parameters
                new { controller = "Account", action = "Edit", EditUser = UrlParameter.Optional } // Parameter defaults
            );

            routes.MapRoute(
               "EditProject", // Route name
               "Project/EditProject/{ProjectId}", // URL with parameters
               new { controller = "Project", action = "EditProject" } // Parameter defaults
           );

            routes.MapRoute(
               "EditLookups", // Route name
               "Project/Lookups/{ProjectId}/{ReturnType}", // URL with parameters
               new { controller = "Project", action = "Lookups", ReturnType = UrlParameter.Optional } // Parameter defaults
           );

            routes.MapRoute(
                "Default", // Route name
                "{controller}/{action}/{id}", // URL with parameters
                new { controller = "Defect", action = "Index", id = UrlParameter.Optional } // Parameter defaults
            );
        }

        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();

            RegisterRoutes(RouteTable.Routes);
        }
    }
}